﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Text;
using com.dz.components;
using com.dz.common;

namespace com.dz.web
{
    public partial class HotBook : BasePage
    {
        const string c_volume_template = "<div class=\"tit3\"><span class=\"f12 fw_n\">{0}</span></div>";
        const string c_chapter_container = "<div id=\"yekacont12\" class=\"bd\"><div class=\"clear\"><table class=\"list-table\"><tbody>{0}</tbody></table></div><div class=\"cb\"></div></div>";
        const string c_chapter = "<td class=\"cc\"><A title=\"点击：{0}  收藏：{1} 字数： {2}\" href=\"/{3}.aspx\" target=\"_blank\" class=\"graylink\">{4}</A></td>";

        BookManager m_book_mgr = new BookManager();
        protected void Page_Load(object sender, EventArgs e)
        {
            BindHotBook();
            if (Token != null)
            {
                lblNickName.Text = string.Format("<script>var nickName='{0}';</script>", Token.NickName);
            }
        }

        /// <summary>
        /// 绑定书籍章节
        /// </summary>
        /// <param name="i_dt_volume"></param>
        /// <param name="i_dt_chapter"></param>
        private void BindHotBook()
        {
            StringBuilder sb = new StringBuilder();

            StringBuilder sb_chapter = new StringBuilder();
            try
            {
                DataSet ds = m_book_mgr.GetHotBookList();
                if (ds == null || ds.Tables[0].Rows.Count <= 0)
                    return;

                int t_total_count = ds.Tables[0].Rows.Count;
                string[] t_title = new string[] { "玄幻奇幻", "武侠仙侠", "都市言情", "历史军事", "游戏竞技", "科幻异灵", "呕心沥血" };




                for (int index = 0; index < t_title.Length; index++)
                {
                    sb.AppendFormat(c_volume_template, t_title[index]);


                    sb_chapter.Append("<tr>");
                    for (int index_chapter = (index) * 30; index_chapter < (index + 1) * 30; index_chapter++)
                    {
                        if (index_chapter % 6 == 0)
                        {
                            sb_chapter.Append("</tr>");
                        }
                        sb_chapter.AppendFormat(c_chapter, ds.Tables[0].Rows[index_chapter]["click"], ds.Tables[0].Rows[index_chapter]["collect"], ds.Tables[0].Rows[index]["wordscount"], ds.Tables[0].Rows[index_chapter]["bookId"], ds.Tables[0].Rows[index_chapter]["bookName"]);
                    }

                    sb_chapter.Append("</tr>");



                    sb.AppendFormat(c_chapter_container, sb_chapter.ToString());
                    sb_chapter = new StringBuilder();
                }
                this.Title = string.Format("{0},免费阅读,热门图书,言情,武侠,都市,历史,军事,科幻,女频,青春,校园,奇幻,最新章节", com.dz.common.AppConfig.SiteName);
            }
            catch (Exception ex)
            {
                LogHelper.Error("绑定章节失败" + ex.ToString());
            }

            lblBook.Text = sb.ToString();
        }
    }
}
